package com.sh;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;

import com.sh.bean.User;
import org.mymybatis.io.Resources;
import org.mymybatis.session.SqlSession;
import org.mymybatis.session.SqlSessionFactory;
import org.mymybatis.session.SqlSessionFactoryBuilder;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class Main {
    public static void main(String[] args) throws IOException, SQLException {

        //读取MyBatis的核心配置文件
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
        SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        User user = new User();
        user.setAge("234");
        user.setUsername("石浩");
        user.setCreated_at("2025-07-4 13:11:28");
        user.setEmail("sdafdsafdsa");
        int insert = sqlSession.insert("com.sh.UserMapper.insertUser", user);
        sqlSession.commit();
        System.out.println("成功插入数据条数：========="+insert);
        User res = (User) sqlSession.selectOne("com.sh.UserMapper.getUserById", 34);
        System.out.println(res);


//        UserMapper userMapper = sqlSession1.getMapper(UserMapper.class);
//        ProductMapper productMapper = sqlSession1.getMapper(ProductMapper.class);
//        DepartmentMapper departmentMapper = sqlSession1.getMapper(DepartmentMapper.class);
//        CacheMapper cacheMapper = sqlSession1.getMapper(CacheMapper.class);
    }

}

